/**
 * @file    TestBin.cpp
 * @brief   Binary array data input test
 * @date    2014/02
 * @version
 * Copyright (c)
 */

#include <iostream>
#include "BinInput.cpp"

int main()
{
	{
		std::string casename = "BO3";
		std::cout << "Scanning the binary output file of case \"" << casename << "\"" << std::endl;

		BinReader Rpt;
		Rpt.Scan(casename); // Scan files first

		std::cout << "Overall grid size=" << Rpt.GrossSize() << ", active grid=" << Rpt.NetSize() << ", number of time step=" << Rpt.NStep() << "\n"
				  << std::endl;

		// show all properties
		std::cout << "Grid static properties: " << std::endl;
		for (const Name_Loc &info : Rpt.stat_props)
		{
			std::cout << "    Name: " << info.name << ", length: " << info.length << ", unit: " << info.unit << ", is at cell center: " << info.on_grid << std::endl;
		}

		std::cout << "Grid dynamic properties: " << std::endl;
		for (const std::vector<Name_Loc> dynamic_infos : Rpt.dym_props)
		{
			if (!dynamic_infos.empty())
			{
				std::cout << "  Time: " << dynamic_infos[0].time << ", time type: " << dynamic_infos[0].time_type << std::endl;
			}
			for (const Name_Loc &info : dynamic_infos)
			{
				std::cout << "    Name: " << info.name << ", length: " << info.length << ", unit: " << info.unit << ", is at cell center: " << info.on_grid << std::endl;
			}
		}

		{ /* Reservoir grid poly data */

			std::cout << std::string(20, '=') << " BASIC XYZ " << std::string(20, '=') << std::endl;
			double x0, y0, d0;
			Rpt.GetAxisOffset(x0, y0, d0);
			std::cout << "Axis_offset=(" << x0 << ", " << y0 << ", " << d0 << ")" << std::endl;

			PropArray GRID_VTX_array;
			bool find_GRID_VTX = Rpt.GetStaticData("GRID_VTX", GRID_VTX_array);

			//////////// 打印节点数组
			std::cout << std::string(20, '=') << " GRID_VTX " << std::string(20, '=') << std::endl;
			if (find_GRID_VTX)
			{
				std::cout << "Find GRID_VTX, length=" << GRID_VTX_array.length << ", number of vertex=" << GRID_VTX_array.length / 3 << std::endl;
			}

			std::cout << "type:" << GRID_VTX_array.type << std::endl;
			std::cout << "GRID_VTX: " << std::endl;
			for (UGINT64 i = 0; i < GRID_VTX_array.length / 3; i++)
			{
				if (i > 10)
					break;
				std::cout << GRID_VTX_array[i * 3] << " " << GRID_VTX_array[i * 3 + 1] << " " << GRID_VTX_array[i * 3 + 2] << std::endl;
			}

			///////////  打印点集做坐标
			std::cout << std::string(20, '=') << " NODE_LIST " << std::string(20, '=') << std::endl;
			PropArray NODE_LIST_array;
			bool find_NODE_LIST = Rpt.GetStaticData("NODE_LIST", NODE_LIST_array);
			if (find_NODE_LIST)
			{
				std::cout << "Find NODE_LIST, length=" << NODE_LIST_array.length << std::endl;
				for (UGINT64 i = 0; i < NODE_LIST_array.length / 8; i++)
				{
					if (i > 10)
						break;
					for (UGINT64 j = 0; j < 8; j++)
					{
						std::cout << NODE_LIST_array[i * 8 + j] << " ";
					}
					std::cout << std::endl;
				}
			}

			if (Rpt.GridType() < 3 && find_GRID_VTX && find_NODE_LIST)
			{
				UGINT64 n_visible_elm = NODE_LIST_array.length / 8;
				std::cout << "\nCorner point grid poly data are complete, NI=" << Rpt.SGridNI() << ", NJ=" << Rpt.SGridNJ() << ", NK=" << Rpt.SGridNK() << ", NLayer=" << Rpt.SGridNK() / Rpt.PoroLvl() << std::endl;
				std::cout << "PoroLvl=" << Rpt.PoroLvl() << ", number of visible element =length(NODE_LIST)/8 =" << n_visible_elm << "\n"
						  << std::endl;
			}
		}

		std::cout << std::string(20, '=') << " PROPERTIES " << std::string(20, '=') << std::endl;

		{ /* static properties */
			PropArray PERMZ_array;
			bool find_PERMZ = Rpt.GetStaticData("PERMZ", PERMZ_array);
			if (find_PERMZ)
			{
				std::cout << "Find PERMZ, length=" << PERMZ_array.length << std::endl;
			}

			for(UGINT64 i = 0; i < PERMZ_array.length; i++){
				if(i > 10)
					break;
				std::cout << PERMZ_array[i] << " ";
			}
		

			PropArray DEPTH_array;
			bool find_DEPTH = Rpt.GetStaticData("DEPTH", DEPTH_array);
			if (find_DEPTH)
			{
				std::cout << "Find DEPTH, length=" << DEPTH_array.length << std::endl;
			}
		}

		{ /*  dynamic properties */
			// SOIL of time step 1 (t = 0)
			PropArray SOIL1_array;
			bool find_SOIL1 = Rpt.GetDynamicData(1, "SOIL", SOIL1_array);
			if (find_SOIL1)
			{
				std::cout << "Find SOIL, length=" << SOIL1_array.length << ", time=" << SOIL1_array.time << std::endl;
			}

			// POIL of time step 2
			PropArray POIL1_array;
			bool find_POIL1 = Rpt.GetDynamicData(2, "POIL", POIL1_array);
			if (find_POIL1)
			{
				std::cout << "Find POIL, length=" << POIL1_array.length << ", time=" << POIL1_array.time << std::endl;
			}

			// POIL of time step 3
			PropArray POIL3_array;
			bool find_POIL3 = Rpt.GetDynamicData(3, "POIL", POIL3_array);
			if (find_POIL3)
			{
				std::cout << "Find POIL, length=" << POIL3_array.length << ", time=" << POIL3_array.time << std::endl;
			}
		}

		Rpt.Clear();
	}

	std::cout << "\nPress any key to quit" << std::endl;

	getchar();
	return 1;
};